﻿using Sw.Hospital.HealthExaminationSystem.Common.Bases;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sw.Hospital.HealthExaminationSystem.DoctorStation
{

    public partial class LY : UserBaseForm
    {

        public LY()
        {
            InitializeComponent();
        }
        string pathLocal = System.AppDomain.CurrentDomain.BaseDirectory + "\\录音程序" + "\\录音文件";
        private void LY_Load(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            RecurseFiles(pathLocal);
        }
        private void RecurseFiles(string path)
        {
            if (string.IsNullOrEmpty(dateTimePicker1.Text))
            {
                MessageBox.Show("请选择开始时间");
            }

            if (string.IsNullOrEmpty(dateTimePicker2.Text))
            {
                MessageBox.Show("请选择结束间");
            }
            DateTime startDate = dateTimePicker1.Value;
            DateTime endDate = dateTimePicker2.Value;
            TimeSpan timeDifference = endDate - startDate;
            int day = timeDifference.Days;
            List<YLList> yLList = new List<YLList>();
            for (int i = 0; i <= day; i++)
            {
                int daysDifference = timeDifference.Days;

                // 获取指定路径下的所有文件，包括子文件夹中的文件
                foreach (string file in Directory.GetFiles(path, "*.wav", SearchOption.AllDirectories))
                {
                    FileInfo fileName = new FileInfo(file);

                    YLList yL = new YLList();

                    yL.录音名称 = fileName.Name;
                    yL.录音时间 = fileName.CreationTime;
                    yL.录音路径 = fileName.FullName;
                    yLList.Add(yL);
                }
            }
            if (yLList.Count > 0)
            {
                dataGridView1.DataSource = yLList;
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            // 检查是否有选中的行
            if (dataGridView1.CurrentRow != null)
            {
                var index = dataGridView1.CurrentRow.Index;

                string Filevalue = dataGridView1["录音路径", index].Value.ToString(); // 获取列的值

                if (simpleButton2.Text == "播放")
                {
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer(Filevalue);

                    player.PlayLooping();
                    simpleButton2.Text = "暂停";
                    // player.Play();
                }
                 else if (simpleButton2.Text == "暂停")
                {
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer(Filevalue);

                    player.Stop();
                    simpleButton2.Text = "播放";

                }

            }
        }

    }
    public partial class YLList
    {
        public string 录音名称 { get; set; }
        public DateTime 录音时间 { get; set; }

        public string 录音路径 { get; set; }

    }
}
